package org.yray.ufiletools.excel;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import org.apache.commons.io.FileUtils;
import org.springframework.util.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ReadExcel {
    public static void main(String[] args) throws IOException {

        List<String> saveList=new ArrayList<>();
        //自定义标题别名
        ExcelReader reader = ExcelUtil.getReader("D://question.xlsx");
        List<List<Object>>  list=reader.read();
        list.forEach(line->{
            String question1=String.valueOf(line.get(3));
            String question2=String.valueOf(line.get(5));
            String answer=line.get(4)+"";
            if(question1.length()>100||question2.length()>100||answer.length()>100)
            {
                return;
            }
            if(!StringUtils.isEmpty(question1))
            {
                saveList.add(question1);
                saveList.add("");
                saveList.add(answer);
                saveList.add("");
            }

            if(!StringUtils.isEmpty(question2))
            {
                saveList.add(question2);
                saveList.add("");
                saveList.add(answer+"");
                saveList.add("");
            }
        });

        FileUtils.writeLines(new File("D://train.txt"),saveList);

    }
}
